package com.nkzy.controller;

import com.nkzy.pojo.Category;
import com.nkzy.pojo.Result;
import com.nkzy.service.CategoryService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Locale;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    //添加文章分类
    @PostMapping
    public Result add(@RequestBody Category category){
        categoryService.add(category);
        return Result.success();
    }
    //查询所有文章分类

    @GetMapping
    public Result list(){
       List<Category> cs= categoryService.list();
       return Result.success(cs);
    }
    //查一个文章分类
    @GetMapping("/detail")
    public Result detail(Integer id){
        Category c=categoryService.findById(id);
        return Result.success(c);
    }
    @PutMapping
    public Result update(@RequestBody @Validated Category category){
        categoryService.update(category);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(Integer id){
        Category c=categoryService.delete(id);
        return Result.success(c);
    }

}
